package com.boco.blch.analysiser.compliance.HW.manager;

import com.boco.blch.analysiser.compliance.ComplianceResolved;
import com.boco.blch.analysiser.util.XmlUtil;

/**
 * HDFS接口认证安全基线要求项   【控制节点】+【数据节点】
 * 【控制节点】
 * /opt/huawei/bigdata/etc/2_20_NameNode/core-site.xml
 * 的配置项hadoop.security.authentication的值是 kerberos
 * 
 * 
 * 【数据节点】
 * /opt/huawei/bigdata/etc/2_20_DateNode/core-site.xml
 * 的配置项hadoop.security.authentication的值是 kerberos
 * @author admin
 *
 */
public class BOCO_Hdfs_IdentityAuth_InterfaceAuth implements ComplianceResolved {

	private final static String name = "hadoop.security.authentication";
	private final static String value = "kerberos";
	
	@Override
	public int realEchoResolved(String echoResult) {
		/*查看/opt/huawei/Bigdata/etc/2_26_Broker/目录下的ENV_VARS里面的变量：HADOOP_SECURITY_AUTHENTICATION的值应该为：kerberos*/
		int result = FAILED;
		if(echoResult != null && echoResult.length() > 0){
			if(echoResult.indexOf("NameNode-start") != -1){//控制节点
				String strResult = echoResult.substring(echoResult.indexOf("NameNode-start")+"NameNode-start".length(), echoResult.indexOf("NameNode-end")).trim();
				result = getResult(strResult);
			}
			if(result == FAILED && echoResult.indexOf("JournalNode-start") != -1){//控制节点
				String strResult = echoResult.substring(echoResult.indexOf("JournalNode-start")+"JournalNode-start".length(), echoResult.indexOf("JournalNode-end")).trim();
				result = getResult(strResult);
			}
			if(result == FAILED && echoResult.indexOf("DataNode-start") != -1){//数据节点
				String strResult = echoResult.substring(echoResult.indexOf("DataNode-start")+"DataNode-start".length(), echoResult.indexOf("DataNode-end")).trim();
				result = getResult(strResult);
			}
		}
		return result;
	}
	
	private int getResult(String echoResult){
		int result = FAILED;
		if(echoResult != null && echoResult.length() > 0){
			String values = XmlUtil.getValueByName(echoResult, name);
			//System.out.println(values);//result = getResult(strResult1);
			if(values!=null && values.equals(value)){
				result = SUCCESS;
			}else{
				result = FAILED;
			}
		}
		return result;
	}
	
	
	

	
}
